Hi Julian,
Unfortunately work notes cannot at this time be added via Inbound Field Rules, so the script include PagerDutyInboundCustomScript must be used instead (in cases like this where inbound field rules are not suitable/possible, this script is the recommended location for customizations to the PagerDuty âž” ServiceNow flow direction).
A common use case is the desire for custom details (which are visible on PagerDuty alerts/incidents that are created via the Events API by monitoring tools) to be made visible on the subsequently created ServiceNow incident. I’ll use that case as an example to illustrate how to leverage PagerDutyInboundCustomScript instead of Inbound Field Rules to create an automated work note. (NOTE: this steps below will only work for incidents that originate in PagerDuty and subsequently create a linked ServiceNow incident, i.e., with a flow of monitoring tool / Events API ➔ PagerDuty ➔ ServiceNow).
Adding a block of code similar to the following example to PagerDutyInboundCustomScript (which is located in ServiceNow under PagerDuty âž” Configuration âž” Configuration files âž” Script Includes (tab)) inside the customPostTransformActivity function - and somewhere below the first if (source.message_type block - will add all custom details (when extant) to the ServiceNow incident as a work note:
else if (source.message_type == "incident.trigger") {
var payload = JSON.parse(source.payload);
if (payload.log_entries[0].channel.hasOwnProperty('details')) {
target.work_notes = payload.log_entries[0].channel.details;
}
}
If you run into any issues with implementation, feel free to reach out to us at support@pagerduty.com - we’d be happy to take a closer look.
The above is accurate as of v7.6 of the PagerDuty app for ServiceNow on Rome.